home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 1992 August
/
info-mac-1992.iso
/
Utilities (util)
/
MacGREP
/
README
< prev
Wrap
Text File
|
1991-04-21
|
4KB
|
78 lines
util/macgrep-02.hqx
MacGREP 0.2
I spent quite a while trying to locate a program on the Macintosh which
performs the same function as "grep" on UNIX systems, namely that one can
output from one file specific lines, which match a specified pattern, to
another file -- a sort of extracting of lines. I finally found a program which
does this on page 117 and 165 of "The C Programming Language" (second edition)
by Kernighan and Ritchie, 1988, Prentice Hall. What I simply did was to port
this small program to the Macintosh while still retaining the UNIX-style
command-line argument function. I also used a modified version of the function
found on page 279 of "Algorithms in C" by Sedgewick, 1990, Addison-Wesley. The
major modifications were to make the program work with 2-byte encoded Japanese
text in SHIFT-JIS code.
As many may know, "grep" is a UNIX function which stands for "global
regular expression print," and is used to print lines from files based on
pattern matching. This particular version of grep only has a few features, and
I plan to add more in the near future.
Now for the instructions. This program, once launched, displays a window
called "console," and a dialog with 3 basic parts:
1) Standard Input
2) Standard Output
3) Command Line
1) Standard Input: 2 choices are given, namely console and file. I wrote the
program so that it takes its input from a file, so be sure to check the file
radio button. At that point you will be prompted to locate the file you wish
to use as input (using the standard Macintosh file system).
2) Standard Output: 4 choices are given, namely console, file, console+file,
and console+printer. Console means that the output of the program will be
displayed in the window called "console." If you choose the output to be placed
in a file, you will be prompted for the file name (using the standard Macintosh
file system). Perhaps the most useful radio button is console+file since it
outputs to both the window and to a file. Note that the number of lines matching
the pattern is also output. This information is appended at the end.
3) Command Line: The first item in the text window is the name of the program
(I call it MacGREP). There are two optional flags you can use:
-n This flag will also print the line number of the input file from which the
line was taken.
-x This flag does an inverse pattern match, namely that all lines which do not
match the pattern will be output.
The only required item (besides the program name which is placed in the text
window by default) is the pattern. This program accepts a single string as a
search pattern. This means you can search for individual letters, parts of a
word, or whole words. It has been written so that it accepts Japanese, and
handles it correctly (the normal algorithms for grep won't).
I would like to mention that the TYPE of the output file (if so chosen)
will be TEXT, but the CREATOR will be ????. This means that in order to view
the ouput of the program you must first launch your favorite text editor or
word processor, then choose OPEN. Double-clicking the file won't open it
(unless you are running an application substitution program like HandOffII).
Programmer's note: I used the ccommand function described on page 171 of
the Think C Standard Libraries Reference. This function handles the command-line
argument handling, and displays the window and dialog. It is quite useful for
running UNIX-based programs on the Macintosh. The source for MacGREP is
included with this bundle.
Please send your comments and suggestions to me at klunde@macc.wisc.edu.
I just ported this program yesterday (4/18/91), and I realize that it needs
more features. I wrote it as a tool for extracting lines from lists of Japanese
words which contain a specific Chinese character (or characters). I will supply
source code upon request. You may distribute the program and its source code
freely as long as ALL of the documentation is included (application, README,
and source code). Parts of this program are copyright Symantec Corporation as
I used Think C 4.0.2 as the development platform.
This program has been stuffed and binhexed. Enjoy!
Ken R. Lunde
klunde@macc.wisc.edu
P.S. A copy of this file will be placed as a README file along with the program
so that one will always have the instructions handy.